﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Gemstone : MonoBehaviour
{

    public int rowIndex = 0;
    public int columnIndex = 0;

    public float xOffset = -6.0f;
    public float yOffset = -4.0f;

    public float scale = 1.2f;

    public GameObject[] gemstoneBgs;
    public int gemstoneType;
    private GameObject gemstoneBg;

    private GameController gameController;

    // Start is called before the first frame update
    void Start()
    {
        gameController = GameObject.Find("GameController").GetComponent<GameController>();
    }

    // Update is called once per frame
    void Update()
    {
        //if (Input.GetKeyDown(KeyCode.Mouse0))
        //{
        //    Debug.Log("Gemstone GetKeyDown");
        //}
    }

    public void UpdatePosition(int rowIndex, int columnIndex)
    {
        this.rowIndex = rowIndex;
        this.columnIndex = columnIndex;

        this.transform.position = new Vector3(columnIndex * scale + xOffset, rowIndex * scale + yOffset);

    } 

    public void RandomCreateGemstoneBg()
    {
        if (gemstoneBg != null)
        {
            return;
        }
        gemstoneType = Random.Range(0, gemstoneBgs.Length);
        gemstoneBg = Instantiate(gemstoneBgs[gemstoneType]) as GameObject;

        gemstoneBg.transform.parent = this.transform;

    }


    // Gemstone添加Box Collider才行
    void OnMouseDown()
    {
        Debug.Log("Gemstone onmousedonwn" + rowIndex + columnIndex);

    }

}
